package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lanou.moving.R;
import com.lanou.moving.entity.SongListClassify;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘琪 on 15/10/27.
 */
public class SongListClassifyAdapter extends BaseAdapter {
    private List<SongListClassify.DataEntity.ChildrenEntity> classifies;
    private SongListClassify.DataEntity.ChildrenEntity classify;
    private Context context;

    public SongListClassifyAdapter(Context context, List<SongListClassify.DataEntity.ChildrenEntity> classifies) {
        this.context = context;
        this.classifies = classifies;
    }

    @Override
    public int getCount() {
        return classifies != null && classifies.size() > 0 ? classifies.size() : 0;
    }

    @Override
    public SongListClassify.DataEntity.ChildrenEntity getItem(int position) {
        return classifies.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.song_list_classify, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        classify = getItem(position);
        if (classify != null) {
            holder.songListItem.setText(classify.getTag());
        }
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'song_list_classifysify.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.song_list_item)
        TextView songListItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
